package com.pms.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.pms.entity.Contact;

import com.pms.entity.UserProject;
import com.pms.service.ContactService;
import com.pms.util.Page;


public class ContactServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String p=request.getParameter("p");
		int pageNum=0;
		if(p==null||"".equals(p)){
			pageNum=1;
			
		}else {
			try {
				pageNum=Integer.parseInt(p);
			} catch (NumberFormatException e) {
				
				pageNum=1;
			}
		}
		HttpSession session=request.getSession();
		UserProject up=(UserProject)session.getAttribute("up");
		String projectId=up.getProject().getProjectId();
		ContactService cs=new ContactService();
        Page<Contact> contactList=cs.findAll(projectId,pageNum);
		session.setAttribute("contactlist", contactList);
		List<Contact> contactList1=cs.findAll(projectId);
		
		for(int i=0;i<contactList1.size();i++){
			Contact contactIndex=(Contact)contactList1.get(0);
			request.setAttribute("contactindex", contactIndex);
			
		}
		
		
		request.getRequestDispatcher("/WEB-INF/views/contact.jsp").forward(request, response);
	}
	
	
	

}
